{include="header"}

<script type="text/javascript">
   function buscar_cliente()
   {
      if(document.f_buscar_cliente.buscar_cliente.value == '')
      {
         $("#search_results_clientes").html('');
      }
      else
      {
         $.ajax({
            type: 'POST',
            url: '{$fsc->url()}',
            dataType: 'html',
            data: $("form[name=f_buscar_cliente]").serialize(),
            success: function(datos) {
               var re = /<!--(.*?)-->/g;
               var m = re.exec( datos );
               if( m[1] == document.f_buscar_cliente.buscar_cliente.value )
               {
                  $("#search_results_clientes").html(datos);
               }
            }
         });
      }
   }
   function buscar_articulo()
   {
      if(document.f_buscar_articulo.buscar_articulo.value == '')
      {
         $("#search_results_articulos").html('');
      }
      else
      {
         $.ajax({
            type: 'POST',
            url: '{$fsc->url()}',
            dataType: 'html',
            data: $("form[name=f_buscar_articulo]").serialize(),
            success: function(datos) {
               $("#search_results_articulos").html(datos);
            }
         });
      }
   }
   $(document).ready(function() {
      $("#b_buscar_cliente").click(function(event) {
         event.preventDefault();
         $("#modal_buscar_cliente").modal('show');
         document.f_buscar_cliente.buscar_cliente.focus();
      });
      $("#f_buscar_cliente").keyup(function() {
         buscar_cliente();
      });
      $("#f_buscar_cliente").submit(function(event) {
         event.preventDefault();
         buscar_cliente();
      });
      $("#b_buscar_articulo").click(function(event) {
         event.preventDefault();
         $("#modal_buscar_articulo").modal('show');
         document.f_buscar_articulo.buscar_articulo.focus();
      });
      $("#f_buscar_articulo").submit(function(event) {
         event.preventDefault();
         buscar_articulo();
      });
      $("#b_borrar_ticket").click(function(event) {
         event.preventDefault();
         window.location.href = "{$fsc->url()}&delete="+prompt('Introduce el código del ticket:');
      });
   });
</script>

<div class="container">
   <div class="row" style="margin-top: 30px; margin-bottom: 30px;">
      <div class="col-md-6">
         <a class="btn btn-block btn-lg btn-default" id="b_buscar_cliente" href="#">
            <span class="glyphicon glyphicon-search"></span> &nbsp; Buscar un cliente
         </a>
      </div>
      <div class="col-md-6">
         <a class="btn btn-block btn-lg btn-default" id="b_buscar_articulo" href="#">
            <span class="glyphicon glyphicon-search"></span> &nbsp; Buscar un artículo
         </a>
      </div>
   </div>
   <div class="row" style="margin-top: 20px; margin-bottom: 20px;">
      <div class="col-md-6">
         <a class="btn btn-block btn-lg btn-danger" id="b_borrar_ticket" href="#">
            <span class="glyphicon glyphicon-trash"></span> &nbsp; Borrar un ticket
         </a>
      </div>
      <div class="col-md-6">
         <a class="btn btn-block btn-lg btn-danger" id="b_cerrar_caja" href="index.php?page=tpv_supermercado&cerrando=TRUE">
            <span class="glyphicon glyphicon-briefcase"></span> &nbsp; Cerrar la caja
         </a>
      </div>
   </div>
</div>

<div class="modal" id="modal_buscar_cliente">
   <div class="modal-dialog" style="width: 99%; max-width: 950px;">
      <div class="modal-content">
         <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h4 class="modal-title">Escribe el DNI del cliente</h4>
         </div>
         <div class="modal-body">
            <form id="f_buscar_cliente" name="f_buscar_cliente" action="{$fsc->url()}" method="post" class="form">
               <div class="container-fluid">
                  <div class="row">
                     <div class="col-lg-12 col-md-12 col-sm-12">
                        <div class="input-group">
                           <input class="form-control" type="text" name="buscar_cliente" size="40" autocomplete="off"/>
                           <span class="input-group-btn">
                              <button class="btn btn-primary" type="submit">
                                 <span class="glyphicon glyphicon-search"></span>
                              </button>
                           </span>
                        </div>
                     </div>
                  </div>
               </div>
            </form>
         </div>
         <div id="search_results_clientes"></div>
      </div>
   </div>
</div>

<div class="modal" id="modal_buscar_articulo">
   <div class="modal-dialog">
      <div class="modal-content">
         <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h4 class="modal-title">Introduce el código de barras</h4>
         </div>
         <div class="modal-body">
            <form id="f_buscar_articulo" name="f_buscar_articulo" action="{$fsc->url()}" method="post" class="form">
               <div class="container-fluid">
                  <div class="row">
                     <div class="col-lg-12 col-md-12 col-sm-12">
                        <div class="input-group">
                           <input class="form-control" type="text" name="buscar_articulo" size="40" autocomplete="off"/>
                           <span class="input-group-btn">
                              <button class="btn btn-primary" type="submit">
                                 <span class="glyphicon glyphicon-search"></span>
                              </button>
                           </span>
                        </div>
                     </div>
                  </div>
               </div>
            </form>
            <div id="search_results_articulos"></div>
         </div>
      </div>
   </div>
</div>

<div class="hidden">
   <iframe src="http://localhost:10080" height="0"></iframe>
</div>

{include="footer"}